package com.oracle.coherence.patterns.security.management.rmi;

import javax.management.remote.JMXConnector;
import javax.management.remote.JMXServiceURL;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Map;

/**
 * -Djavax.net.ssl.trustStore=jmx.jks
 * -Djavax.net.ssl.trustStorePassword=splash.target
 * -Djmx.remote.protocol.provider.pkgs=com.oracle.coherence.patterns.security.management
 *
 * @author Jonathan Knight
 */
public class ClientProvider extends com.sun.jmx.remote.protocol.rmi.ClientProvider {

    @Override
    @SuppressWarnings({"unchecked"})
    public JMXConnector newJMXConnector(JMXServiceURL serviceURL, Map environment) throws IOException {
        if (!serviceURL.getProtocol().equals("rmi")) {
            throw new MalformedURLException("The service URL protocol must be rmi: " + serviceURL.getProtocol());
        }

        return new KrbRMIConnector(serviceURL, environment);
    }

}